import React, { Component } from 'react'
import { Button, Table, Modal, Row, Col, Popconfirm, Input, Form, message } from 'antd';
import { connect } from 'react-redux';
// import { actionCreators } from './store';
import { findPublished, } from '../../../api/resourceCategory/resourceCategory'

class Published extends Component {
  constructor() {
    super()
    this.state = {
      dataSource: [],
      publishShow: false,
      editShow: false,
      paginationNo: {
        pageSize: 10,
        defaultCurrent:1,
        current:1,
      },
      columns : [
        {
          title:'发布时间',key:'publish_time',dataIndex:'publish_time',
        },
        {
          title: '操作',dataIndex: 'action',key: 'action',width: 220,
          render: (text, record) => 
            <Popconfirm
              title="确认下架吗?" okText="确定" cancelText="取消"
              onConfirm={() => this.handleOffshelf(record)}
            >
              <Button size="small" type="link" >下架</Button>
            </Popconfirm>
        }
      ]
    }
  }

  getPublished = (number, page, pageSize) => {
    findPublished({pageNum: page, pageSize: pageSize, number}).then(res => {
      if(res.data.metaData.code === 'success') {
        const paginationNo = this.state.paginationNo
        paginationNo.total = res.data.data.total
        paginationNo.current = res.data.data.pageNum
        this.setState({dataSource: res.data.data.list})
      }
    })
  }

  componentWillMount() {
      console.log('this.props.baseCOlumns', this.props.baseColumns)
      this.setState({
        columns: [...this.props.baseColumns ,...this.state.columns]
      })
      this.getPublished('01010101', 1,10)    
  }
  handleOffshelf = record => {
    console.log('off shelf', record)
  }
  render() {
    const  {  columns, dataSource } = this.state
    return (
      <div>
        <Table
          size="small" loading={this.state.loading}
          dataSource={dataSource}
          columns={columns} bordered rowKey={record => record.taskId} 
          style={{ padding: 20 }}
          pagination={this.state.paginationNo} />
      </div>
    )
  }
}

export default Published


